package org.dromara.business.task;

import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
import com.aizuda.snailjob.client.model.ExecuteResult;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.dromara.business.thirdparty.StatisticsService;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


/**
 * 每小时推送数据到Telegram定时器
 */
@Slf4j
@Component
@JobExecutor(name = "pushTelegramHorsTask")
public class PushTelegramHorsTask {

    @Resource
    private StatisticsService statisticsService;

    public ExecuteResult jobExecute(JobArgs jobArgs) {
        log.info("开始执行每小时推送数据到Telegram定时任务，执行时间：{}", LocalDateTime.now());
        try {
            statisticsService.sendHourlyStatistics();
            log.info("每小时推送数据到Telegram定时任务执行成功");
            return ExecuteResult.success("每小时推送数据到Telegram执行成功");
        } catch (Exception e) {
            log.error("每小时推送数据到Telegram定时任务执行失败", e);
            return ExecuteResult.success("每小时推送数据到Telegram执行失败");
        }
    }
}
